﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(SpwanModle), true)]
public class SpwanTempletEditor : Editor
{
    private SpwanModle m_Script;

    private GUIStyle m_HandleLable = new GUIStyle();

    public enum enumType
    {
        点序,    
        顶点位置,
        UV,
        法线
    }

    private enumType m_TempletType = enumType.点序;

    private void Awake()
    {
        m_Script = target as SpwanModle;
        m_HandleLable.normal.textColor = Color.red;
        m_HandleLable.fontSize = 15;
    }


    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("数据"))
        {
            //Debug.LogError("加载保存数据");
            Debug.Log("总共顶点数："+ m_Script.m_Filter.mesh.vertexCount +"三角面数 :" + m_Script.m_Filter.mesh.triangles.Length);
        }
        //if(GUILayout.)
        m_TempletType = (enumType)EditorGUILayout.EnumPopup("检视类型：", m_TempletType);
        base.OnInspectorGUI();
    }


    void OnSceneGUI()
    {
        //for (int i = m_Script.TempletMesh.mesh.vertexCount / 2; i < m_Script.TempletMesh.mesh.vertexCount; i++) {
        for (int i = 0; i < m_Script.m_Filter.mesh.vertexCount; i++){
            Vector3 localPos = m_Script.m_Filter.mesh.vertices[i];
            switch (m_TempletType) {
                case enumType.点序:
                    Handles.Label(m_Script.gameObject.transform.TransformPoint(localPos), i + "", m_HandleLable);
                    break;
                case enumType.顶点位置:
                    Handles.Label(m_Script.gameObject.transform.TransformPoint(localPos), localPos.ToString(), m_HandleLable);
                    break;
                case enumType.UV:
                    Vector2 uv = m_Script.m_Filter.mesh.uv[i];
                    Handles.Label(m_Script.gameObject.transform.TransformPoint(localPos), uv.ToString(), m_HandleLable);
                    break;
                case enumType.法线:
                    Vector2 normal = m_Script.m_Filter.mesh.normals[i];
                    Handles.Label(m_Script.gameObject.transform.TransformPoint(localPos), normal.ToString(), m_HandleLable);
                    break;
            }
        }
    }
}
